package com.app.utils;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Environment;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.TextAppearanceSpan;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.app.application.QXApplication;
import com.app.config.ApplicationConfig;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import phone.qyg.com.qyg.R;

import static com.app.application.QXApplication.getContext;

@SuppressWarnings("deprecation")
public class CommonUtil {

	public static final String APP_HOST_PATH = Environment
			.getExternalStorageDirectory()
			+ File.separator
			+ QXApplication.getContext().getPackageName();

	public static final String APP_HOST_PATH_APK = CommonUtil.getSDPath()
			+ File.separator
			+ ApplicationConfig.SD_FIEL_NAME_FILE;

	public static final String APP_HOST_PATH_SHARED_ICON = Environment
			.getExternalStorageDirectory()
			+ File.separator
			+ QXApplication.getContext().getPackageName()
			+ File.separator
			+ "img";

	public static final String DOWNLOAD_DIR = APP_HOST_PATH + File.separator
			+ "download";

	public static final String DOC_DIR = APP_HOST_PATH + File.separator
			+ "download" + File.separator + "doc";

	public static final String DOWNLOAD_DIR_VIDEO = DOWNLOAD_DIR
			+ File.separator + "video";

	public static long create_time_defalut = 4100515200000l;

	public static void showInfoDialog(Context context, String message) {
		showInfoDialog(context, message, "提示", "确定", null);
	}

	public static float getDimens(int resId) {
		return QXApplication.getContext().getResources().getDimension(resId);
	}

	public static void showInfoDialog(Context context, String message,
			String titleStr, String positiveStr,
			DialogInterface.OnClickListener onClickListener) {
		AlertDialog.Builder localBuilder = new AlertDialog.Builder(context);
		localBuilder.setTitle(titleStr);
		localBuilder.setMessage(message);
		if (onClickListener == null)
			onClickListener = new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {

				}
			};
		localBuilder.setPositiveButton(positiveStr, onClickListener);
		localBuilder.show();
	}

	public static String md5(String paramString) {
		String returnStr;
		try {
			MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
			localMessageDigest.update(paramString.getBytes());
			returnStr = byteToHexString(localMessageDigest.digest());
			return returnStr;
		} catch (Exception e) {
			return paramString;
		}
	}

	/**
	 * 获取文件大小
	 * 
	 * @param f
	 * @return
	 */
	public static long getFileSize(File f) {
		long size = 0;
		try {
			File flist[] = f.listFiles();
			for (int i = 0; i < flist.length; i++) {
				if (flist[i].isDirectory()) {
					size = size + getFileSize(flist[i]);
				} else {
					size = size + flist[i].length();
				}
			}
		} catch (Exception e) {
		}
		return size;
	}


	/**
	 * 格式化单位
	 * 
	 * @param size
	 * @return
	 */
	public static String getFormatSize(double size) {
		double kiloByte = size / 1024;
		if (kiloByte < 1) {
			return size + "B";
		}

		double megaByte = kiloByte / 1024;
		if (megaByte < 1) {
			BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
			return result1.setScale(2, BigDecimal.ROUND_HALF_UP)
					.toPlainString() + "KB";
		}

		double gigaByte = megaByte / 1024;
		if (gigaByte < 1) {
			BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
			return result2.setScale(2, BigDecimal.ROUND_HALF_UP)
					.toPlainString() + "MB";
		}

		double teraBytes = gigaByte / 1024;
		if (teraBytes < 1) {
			BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
			return result3.setScale(2, BigDecimal.ROUND_HALF_UP)
					.toPlainString() + "GB";
		}
		BigDecimal result4 = new BigDecimal(teraBytes);
		return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()
				+ "TB";
	}

	/**
	 * 将指定byte数组转换成16进制字符串
	 * 
	 * @param b
	 * @return
	 */
	public static String byteToHexString(byte[] b) {
		StringBuffer hexString = new StringBuffer();
		for (int i = 0; i < b.length; i++) {
			String hex = Integer.toHexString(b[i] & 0xFF);
			if (hex.length() == 1) {
				hex = '0' + hex;
			}
			hexString.append(hex.toUpperCase());
		}
		return hexString.toString();
	}

	/**
	 * 当前网络状态
	 * @param context
	 * @return 0-没有网 1-wifi 2-手机网络
     */
	public static int isNetworkAvailable(Context context) {
		ConnectivityManager connectivity = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connectivity == null) {
			return 0;
		} else {
			NetworkInfo[] info = connectivity.getAllNetworkInfo();
			if (info != null) {
				for (int i = 0; i < info.length; i++) {
					if (info[i].getState() == NetworkInfo.State.CONNECTED) {
						NetworkInfo netWorkInfo = info[i];
						if (netWorkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
							return 1;
						} else if (netWorkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
							String extraInfo = netWorkInfo.getExtraInfo();
							if ("cmwap".equalsIgnoreCase(extraInfo)
									|| "cmwap:gsm".equalsIgnoreCase(extraInfo)) {
								return 2;
							}
							return 3;
						}
					}
				}
			}
		}
		return 0;
	}

	public static String getStringDate() {
		Date currentTime = new Date();
		@SuppressLint("SimpleDateFormat") SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return formatter.format(currentTime);
	}

	public static String getLongTimeChangeStringYYMMMDD(long longtime) {
		Date dat = new Date(longtime);
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(dat);
		@SuppressLint("SimpleDateFormat") SimpleDateFormat format = new SimpleDateFormat(
				"yyyy-MM-dd");
		return format.format(gc.getTime());
	}

	public static String getLongTimeChangeStringYYMMMDDHHMMSS(long longtime) {
		Date dat = new Date(longtime);
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(dat);
		@SuppressLint("SimpleDateFormat") SimpleDateFormat format = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		return format.format(gc.getTime());
	}

	public static String getLongTimeChangeStringMMDD(long longtime) {
		Date dat = new Date(longtime);
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(dat);
		@SuppressLint("SimpleDateFormat") SimpleDateFormat format = new SimpleDateFormat(
				"MM-dd");
		return format.format(gc.getTime());
	}

	public static long getYMDHMSChangesLogn(String time){
		long timemillis = 0;
		try {
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = null;
			date = simpleDateFormat.parse(time);
			timemillis = date.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return  timemillis;
	}

	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}

	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}

	/**
	 * 将px值转换为sp值，保证文字大小不变
	 */
	public static int px2sp(Context context, float pxValue) {
		final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
		return (int) (pxValue / fontScale + 0.5f);
	}

	/**
	 * 将sp值转换为px值，保证文字大小不变
	 */
	public static int sp2px(Context context, float spValue) {
		final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
		return (int) (spValue * fontScale + 0.5f);
	}

	public static int getScreenPicHeight(int screenWidth, Bitmap bitmap) {
		int picWidth = bitmap.getWidth();
		int picHeight = bitmap.getHeight();
		int picScreenHeight = 0;
		picScreenHeight = (screenWidth * picHeight) / picWidth;
		return picScreenHeight;
	}

	@SuppressWarnings("deprecation")
	private static Drawable createDrawable(Drawable d, Paint p) {

		BitmapDrawable bd = (BitmapDrawable) d;
		Bitmap b = bd.getBitmap();
		Bitmap bitmap = Bitmap.createBitmap(bd.getIntrinsicWidth(),
				bd.getIntrinsicHeight(), Config.RGB_565);
		Canvas canvas = new Canvas(bitmap);
		canvas.drawBitmap(b, 0, 0, p); // 关键代码，使用新的Paint画原图，

		return new BitmapDrawable(bitmap);
	}

	public static StateListDrawable createSLD(Context context, Drawable drawable) {
		StateListDrawable bg = new StateListDrawable();
		int brightness = 50 - 127;
		ColorMatrix cMatrix = new ColorMatrix();
		cMatrix.set(new float[] { 1, 0, 0, 0, brightness, 0, 1, 0, 0,
				brightness,// 改变亮度
				0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 });

		Paint paint = new Paint();
		paint.setColorFilter(new ColorMatrixColorFilter(cMatrix));

		Drawable normal = drawable;
		Drawable pressed = createDrawable(drawable, paint);
		bg.addState(new int[] { android.R.attr.state_pressed, }, pressed);
		bg.addState(new int[] { android.R.attr.state_focused, }, pressed);
		bg.addState(new int[] { android.R.attr.state_selected }, pressed);
		bg.addState(new int[] {}, normal);
		return bg;
	}

	public static Bitmap getImageFromAssetsFile(Context ct, String fileName) {
		Bitmap image = null;
		AssetManager am = ct.getAssets();
		try {
			InputStream is = am.open(fileName);
			image = BitmapFactory.decodeStream(is);
			is.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return image;

	}

	public static String getUploadtime(long created) {
		StringBuffer when = new StringBuffer();
		int difference_seconds;
		int difference_minutes;
		int difference_hours;
		int difference_days;
		int difference_months;
		long curTime = System.currentTimeMillis();
		difference_months = (int) (((curTime / 2592000) % 12) - ((created / 2592000) % 12));
		if (difference_months > 0) {
			when.append(difference_months + "月");
		}

		difference_days = (int) (((curTime / 86400) % 30) - ((created / 86400) % 30));
		if (difference_days > 0) {
			when.append(difference_days + "天");
		}

		difference_hours = (int) (((curTime / 3600) % 24) - ((created / 3600) % 24));
		if (difference_hours > 0) {
			when.append(difference_hours + "小时");
		}

		difference_minutes = (int) (((curTime / 60) % 60) - ((created / 60) % 60));
		if (difference_minutes > 0) {
			when.append(difference_minutes + "分钟");
		}

		difference_seconds = (int) ((curTime % 60) - (created % 60));
		if (difference_seconds > 0) {
			when.append(difference_seconds + "秒");
		}

		return when.append("前").toString();
	}

	public static void setListViewHeightBasedOnChildren(ListView listView) {
		ListAdapter listAdapter = listView.getAdapter();
		if (listAdapter == null) {
			return;
		}
		int totalHeight = 0;
		for (int i = 0; i < listAdapter.getCount(); i++) {
			View listItem = listAdapter.getView(i, null, listView);
			listItem.measure(0, 0);
			totalHeight += listItem.getMeasuredHeight();
		}
		ViewGroup.LayoutParams params = listView.getLayoutParams();
		params.height = totalHeight
				+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));

		listView.setLayoutParams(params);
	}

	public static int setListViewHeightBasedOnChildren1(ListView listView) {
		ListAdapter listAdapter = listView.getAdapter();
		if (listAdapter == null) {
			return 0;
		}

		int totalHeight = 0;
		for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
			View listItem = listAdapter.getView(i, null, listView);
			listItem.measure(0, 0);
			totalHeight += listItem.getMeasuredHeight();
		}

		ViewGroup.LayoutParams params = listView.getLayoutParams();
		params.height = totalHeight
				+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
		listView.setLayoutParams(params);
		return params.height;
	}

	public static String formatDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		return sdf.format(new Date());
	}

	public static void runOnUIThread(Runnable run) {
		QXApplication.getMainHandler().post(run);
	}


	/**
	 * 应用当前版本号
     */
	public static String applicationVersion() {
		String version = "0";
		try {
			PackageManager packageManager = QXApplication.getContext()
					.getPackageManager();
			PackageInfo packageInfo = packageManager.getPackageInfo(
					QXApplication.getContext().getPackageName(), 0);
			version = packageInfo.versionName;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return version;
	}

	public static boolean isRequestStr(String requestStr) {
		return (requestStr != null && requestStr.length() > 0 && !requestStr
				.equals("[]"));
	}

	public static <T> boolean isRequestList(List<T> requestList) {
		return (requestList != null && !requestList.isEmpty());
	}

	public static boolean isNetWork() {
		int networkAvailable = isNetworkAvailable(QXApplication.getContext());
		if (networkAvailable != 0)
			return true;
		else
			return false;
	}

	public static int getScreentWidth() {
		DisplayMetrics displayMetrics = QXApplication.getContext()
				.getResources().getDisplayMetrics();
		return displayMetrics.widthPixels;
	}


	public static int getScreentHeight() {
		DisplayMetrics displayMetrics = QXApplication.getContext()
				.getResources().getDisplayMetrics();
		return displayMetrics.heightPixels;
	}

	public static String Join(String join, List<String> strs) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < strs.size(); i++) {
			if (i == (strs.size() - 1)) {
				sb.append(strs.get(i));
			} else {
				sb.append(strs.get(i)).append(join);
			}
		}
		return new String(sb);
	}

	/**
	 * 方向是 4--6 2--8
	 * @param textView
	 * @param direction
	 * @param resourceIndex
     */
	public static void setTextViewDrawableDirection(TextView textView,int direction, int resourceIndex) {
		Drawable drawable = null;
		drawable = getContext().getResources().getDrawable(resourceIndex);
		drawable.setBounds(0, 0, drawable.getMinimumWidth(),
				drawable.getMinimumHeight());
		if(direction == 8){
			textView.setCompoundDrawables(null, drawable, null, null);
		}else if(direction == 6){
			textView.setCompoundDrawables(null, null, drawable, null);
		}else if(direction == 2){
			textView.setCompoundDrawables(null, null, null, drawable);
		}else{
			textView.setCompoundDrawables(drawable, null, null, null);
		}

	}

	public static void setTextViewDrawableLeftRight(TextView textView,
			int resourceIndex) {
		Drawable drawable = null;
		drawable = getContext().getResources().getDrawable(resourceIndex);
		drawable.setBounds(0, 0, drawable.getMinimumWidth(),
				drawable.getMinimumHeight());
		textView.setCompoundDrawables(drawable, null, null, null);
	}

	public static void deleteFile(File file) {
		if (file.isFile()) {
			deleteFileSafely(file);
			return;
		}
		if (file.isDirectory()) {
			File[] childFiles = file.listFiles();
			if (childFiles == null || childFiles.length == 0) {
				deleteFileSafely(file);
				return;
			}
			for (int i = 0; i < childFiles.length; i++) {
				deleteFile(childFiles[i]);
			}
			deleteFileSafely(file);
		}
	}

	/**
	 * 安全删除文件.
	 * 
	 * @param file
	 * @return
	 */
	public static boolean deleteFileSafely(File file) {
		if (file != null) {
			String tmpPath = file.getParent() + File.separator
					+ System.currentTimeMillis();
			File tmp = new File(tmpPath);
			file.renameTo(tmp);
			boolean isDelete = tmp.getAbsoluteFile().delete();
			System.gc();
			return isDelete;
		}
		return false;
	}

	/**
	 * 递归删除文件和文件夹
	 * @param file    要删除的根目录
	 */
	public static void RecursionDeleteFile(File file){
		if(file.isFile()){
			file.delete();
			return;
		}
		if(file.isDirectory()){
			File[] childFile = file.listFiles();
			if(childFile == null || childFile.length == 0){
				file.delete();
				return;
			}
			for(File f : childFile){
				RecursionDeleteFile(f);
			}
			file.delete();
		}
	}


	public static void savePic(Bitmap b, String filePath, String fileName) {
		File f = new File(filePath);
		if (!f.exists()) {
			f.mkdirs();
		}
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(filePath + File.separator + fileName);
			if (null != fos) {
				b.compress(Bitmap.CompressFormat.PNG, 100, fos);
				fos.flush();
				fos.close();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	/**
	 * 校验身份证合法性
	 * @param codeNum
	 * @return
     */
	public static boolean isCodeLegal(String codeNum){
		//定义判别用户身份证号的正则表达式（要么是15位，要么是18位，最后一位可以为字母）
		Pattern idNumPattern = Pattern.compile("(\\d{14}[0-9a-zA-Z])|(\\d{17}[0-9a-zA-Z])");
		//通过Pattern获得Matcher
		Matcher idNumMatcher = idNumPattern.matcher(codeNum);
		return idNumMatcher.matches();
	}

	/**
	 * 验证手机格式
	 */
	public static boolean isMobileFormatNO(String format,String mobiles) {
		/*
		 * 移动：134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
		 * 联通：130、131、132、152、155、156、185、186 电信：133、153、180、189、（1349卫通）
		 * 总结起来就是第一位必定为1，第二位必定为3,4或5或8或7，其他位置的可以为0-9
		 */
		String telRegex = "[1][34578]\\d{9}";// "[1]"代表第1位为数字1，"[358]"代表第二位可以为3、4/5、7,8中的一个，"\\d{9}"代表后面是可以是0～9的数字，有9位。
		if (TextUtils.isEmpty(mobiles))
			return false;
		else
			return mobiles.matches(isRequestStr(format)?format:telRegex);
	}
	/**
	 * 验证手机格式
	 */
	public static boolean isMobileNO(String mobiles) {
		/*
		 * 移动：134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
		 * 联通：130、131、132、152、155、156、185、186 电信：133、153、180、189、（1349卫通）
		 * 总结起来就是第一位必定为1，第二位必定为3,4或5或8或7，其他位置的可以为0-9
		 */
		String telRegex = "[1][34578]\\d{9}";// "[1]"代表第1位为数字1，"[358]"代表第二位可以为3、4/5、7,8中的一个，"\\d{9}"代表后面是可以是0～9的数字，有9位。
		if (TextUtils.isEmpty(mobiles))
			return false;
		else
			return mobiles.matches(telRegex);
	}

	/**
	 * 密码校验  数字+字母
	 */
	public static boolean isPassNO(String mobiles) {
		return Pattern.matches("(([a-z]+[0-9]+)|([0-9]+[a-z]+))[a-z0-9]*$",mobiles);
	}

	/**
	 * 判断一个字符串的位数
	 * @param str
	 * @param length
	 * @return
	 */
	public static boolean isMatchLength(String str, int length) {
		if (str.isEmpty()) {
			return false;
		} else {
			return str.length() == length ? true : false;
		}
	}

	/**
	 * 设置界面文字展示 统一使用html封装
	 * @param textView
	 * @param content
	 */
	public static void textViewSetText(TextView textView, String content){
		if(isRequestStr(content)){
			Spanned fromHtml = Html.fromHtml(content);
			textView.setText(fromHtml);
		}else{
			textView.setText(setAttributeText(content));
		}
	}

	/**
	 * 获取的属性 为空转化为""
	 * @param attribute
	 * @return
	 */
	public static String setAttributeText(Object attribute){
		String str = (attribute == null) ?"":attribute.toString();
		return str;
	}

	/**
	 * 格式化数据
	 * @param temp
	 * @return
     */
	public static String formatStr(int temp){
		Format format = new DecimalFormat("00");
		String str = format.format(temp);
		return str;
	}


	/**
	 * 判断字符是否为存字符
	 * @param str
	 * @return
     */
	public static boolean isNumeric(String str){
		if(!isRequestStr(str))
			return  false;
		Pattern pattern = Pattern.compile("[0-9]*");
		Matcher isNum = pattern.matcher(str);
		if( !isNum.matches() ){
			return false;
		}
		return true;
	}

	/**
	 * 集合转化 去除首尾
	 * @param temps
	 * @return
     */
	public static String listDelHeadEndChangeStr(List temps){
		String endStr = "";
		if(CommonUtil.isRequestList(temps)){
			String str = temps.toString();
			endStr = str.substring(1, (str.length() -1));
		}
		return endStr;
	}

	public static String listToString(List list, char separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			sb.append(list.get(i));
			if (i < list.size() - 1) {
				sb.append(separator);
			}
		}
		return sb.toString();
	}


	/**
	 * 手机号进行替换 加密
	 * @param phone
	 * @return
     */
	public static String phonePass(String phone){
		String phonePass = "";
		if(isRequestStr(phone) && phone.length()==11){
			StringBuilder sb = new StringBuilder(phone);
			phonePass = sb.replace(3, 7, "****").toString();
		}
		return phonePass;
	}

	/**
	 * 获取版本号
	 * @return 当前应用的版本号
	 */
	public static String getVersion() {
		String version = "1.0.1";
		try {
			PackageManager manager = QXApplication.getContext().getPackageManager();
			PackageInfo info = manager.getPackageInfo(QXApplication.getContext().getPackageName(), 0);
			version = info.versionName;

		} catch (Exception e) {
			e.printStackTrace();
//			return QXApplication.getContext().getString(R.string.can_not_find_version_name);
		}
		return version;
	}

	/**
	 * 获取sd卡路径
	 * @return
     */
	public static String getSDPath(){
		File sdDir = null;
		boolean sdCardExist = Environment.getExternalStorageState()
				.equals(Environment.MEDIA_MOUNTED);//判断sd卡是否存在
		String sdPath = "";
		if(sdCardExist)
		{
			sdDir = Environment.getExternalStorageDirectory();//获取跟目录
			sdPath = sdDir.toString();
		}
		return sdPath;
	}

	public static String deletePrice(String price){
		String tempPrice = "0";
		if(isRequestStr(price) && price.contains("￥")){
			tempPrice = price.replace("￥","");
		}
		return tempPrice;
	}

	/**
	 * 弹出确定框
	 * @param context
	 * @param msg
	 * @param title
	 * @param content
	 */
	public static void showAlertDialog(final Context context, String msg, String title, final String content){
		android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
		builder.setMessage(msg);
		builder.setTitle(title);
		builder.setPositiveButton(context.getString(R.string.sure), new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				Intent intent = new Intent(Intent.ACTION_DIAL);
				Uri data = Uri.parse("tel:" + content);
				intent.setData(data);
				context.startActivity(intent);
			}
		});
		builder.setNegativeButton(context.getString(R.string.quit), new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		builder.create().show();
	}

	/**
	 * 判断手机号码是否合理
	 *
	 * @param phoneNums
	 */
	public static boolean judgePhoneNums(String phoneNums) {
		if (CommonUtil.isMatchLength(phoneNums, 11)
				&& CommonUtil.isMobileNO(phoneNums)) {
			return true;
		}
		PromptManager.showToast(R.string.mobile_phone_format_is_wrong);
		return false;
	}

	/**
	 * 测试:(0) 工具类
	 */
	public static void setTextReplace(TextView view ,int resId,String content) {
		if(resId<=0)return;

		String str = (content == null) ?"":content;
		if(resId >0)
			str = MessageFormat.format(QXApplication.getContext().getResources().getString(resId),content);
		view.setText(str);
	}


	public static SpannableString setMemSpannAddCout(String index, String all){
		StringBuffer buffer = new StringBuffer(String.valueOf(index));

		int indexLength = buffer.length();

		buffer.append(String.valueOf("\n")).append(all);

		int allLength = buffer.length();

		//设置文字大小 颜色改变
		SpannableString styledText = new SpannableString(buffer.toString());
		styledText.setSpan(new TextAppearanceSpan(QXApplication.getContext(), R.style.venue_title_one), 0, indexLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

		styledText.setSpan(new TextAppearanceSpan(QXApplication.getContext(), R.style.venue_title_two), indexLength, allLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);


		return styledText;
	}
}
